home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hamradio / sgp4_pl2.zip / SUPPORT.PAS < prev   
Pascal/Delphi Source File  |  1992-09-14  |  12KB  |  501 lines

  1. Unit Support;  (** This unit contains machine-specific code **)
  2. {           Author:  Dr TS Kelso }
  3. { Original Version:  1992 Jun 25 }
  4. { Current Revision:  1992 Sep 14 }
  5. {          Version:  1.81 }
  6. {        Copyright:  1992, All Rights Reserved }
  7. {$N+}
  8.  
  9. INTERFACE
  10.  
  11. const  {IBM PC screen codes}
  12.   BS       =  ^H;                      {Backspace}
  13.   CR       =  ^M;                      {Carriage Return}
  14.   CRLF     =  ^M^J;                    {Carriage Return/Line Feed}
  15.   BELL     =  ^G;                      {Terminal Bell}
  16.   ESC      =  ^[;                      {Escape}
  17.   DEL      =  #$7F;                    {Delete}
  18.   Up       =  #72;                     {Up Cursor}
  19.   Dn       =  #80;                     {Down Cursor}
  20.   Rt       =  #77;                     {Right Cursor}
  21.   Lt       =  #75;                     {Left Cursor}
  22.   Home     =  #71;                     {Home Key}
  23.   Endd     =  #79;                     {End Key}
  24.   PgUp     =  #73;                     {Page Up}
  25.   PgDn     =  #81;                     {Page Down}
  26.   C_Lt     =  #115;                    {Control-Left Cursor}
  27.   C_Rt     =  #116;                    {Control-Right Cursor}
  28.   C_PgUp   =  #132;                    {Control-Page Up}
  29.   C_PgDn   =  #118;                    {Control-Page Down}
  30.   UpDown   =  #24#25;                  {Up/Down Arrows}
  31.   Cursors  =  #24#25#26#27;            {Up/Down/Left/Right Arrows}
  32.   SFrame : string = '┌─┐│└┘┴┬├┼┤';     {Single-Line Frame Characters}
  33.   DFrame : string = '╔═╗║╚╝╩╦╠╬╣';     {Double-Line Frame Characters}
  34.   MFrame : string = '╡╞╕╛╘╒';          {Mixed-Line Frame Characters}
  35.  
  36. type
  37.   options  = array [0..10] of string;
  38.   time_set = record
  39.     yr,mo,dy,hr,mi,se,hu : word;
  40.     end; {record}
  41.  
  42. Procedure Cursor_On;
  43. Procedure Cursor_Off;
  44. Procedure Save_Cursor;
  45. Procedure Restore_Cursor;
  46. Procedure ReverseVideo;
  47. Procedure NormalVideo;
  48. Procedure BoldVideo;
  49. Procedure FrameWindow(x,y,w,h,color : byte; title : string);
  50. Procedure MakeWindow(x,y,w,h,color : byte; title : string);
  51. Procedure ClearWindow(x,y,w,h : byte);
  52. Procedure Show_Status_Line(title : string);
  53. Procedure Show_Instructions(title : string);
  54. Procedure Clear_Status_Line;
  55. Procedure Report_Error(x,y : byte; title : string);
  56. Procedure Beep;
  57. Procedure Buzz;
  58. Procedure Mark_Time;
  59. Procedure Zero_Time(var time : time_set);
  60. Procedure Get_Current_Time(var time : time_set);
  61. Function Yes : boolean;
  62. Function TwoDigit(arg : integer) : string;
  63. Function ThreeDigit(arg : integer) : string;
  64. Procedure Convert_Blanks(var field : string);
  65. Function Integer_Value(buffer : string;
  66.                  start,length : integer) : integer;
  67. Function Real_Value(buffer : string;
  68.               start,length : integer) : double;
  69. Function File_Exists(filename : string) : boolean;
  70. Function Select_File(title,pattern,default : string; x,y,w,h : byte) : string;
  71. Function Select_Option(menu : options; number,x,y,w,h : byte) : byte;
  72.  
  73. IMPLEMENTATION
  74.   Uses CRT,DOS,MinMax;
  75.  
  76. var
  77.   Last_X,Last_Y : byte;
  78.  
  79. Procedure Cursor_On;
  80.   var
  81.     regs : registers;
  82.   begin
  83.   with regs do
  84.     begin
  85.     ah := $01;
  86.     ch := 0;
  87.     cl := 7;
  88.     end; {with}
  89.   Intr($10,regs);
  90.   end; {Procedure Cursor_On}
  91.  
  92. Procedure Cursor_Off;
  93.   var
  94.     regs : registers;
  95.   begin
  96.   with regs do
  97.     begin
  98.     ah := $01;
  99.     ch := $20;
  100.     cl := $00;
  101.     end; {with}
  102.   Intr($10,regs);
  103.   end; {Procedure Cursor_Off}
  104.  
  105. Procedure Save_Cursor;
  106.   begin
  107.   Last_X := WhereX;
  108.   Last_Y := WhereY;
  109.   end; {Procedure Save_Cursor}
  110.  
  111. Procedure Restore_Cursor;
  112.   begin
  113.   GotoXY(Last_X,Last_Y);
  114.   end; {Procedure Restore_Cursor}
  115.  
  116. Procedure ReverseVideo;
  117.   begin
  118.   TextColor(black);
  119.   TextBackground(lightgray);
  120.   end; {Procedure ReverseVideo}
  121.  
  122. Procedure NormalVideo;
  123.   begin
  124.   TextColor(lightgray);
  125.   TextBackground(black);
  126.   end; {Procedure NormalVideo}
  127.  
  128. Procedure BoldVideo;
  129.   begin
  130.   TextColor(yellow);
  131.   TextBackground(black);
  132.   end; {Procedure BoldVideo}
  133.  
  134. Procedure FrameWindow(x,y,w,h,color : byte;
  135.                               title : string);
  136.   var
  137.     i : byte;
  138.   begin
  139. {  Window(x,y,x+w+3,y+h+1);}
  140. {  ClrScr; }
  141.   Window(x,y,x+w+3,y+h+2);
  142.   TextColor(color);
  143.   Write(DFrame[1]);
  144.   for i := 1 to w+2 do
  145.     Write(DFrame[2]);
  146.   Write(DFrame[3]);
  147.   for i := 1 to h do
  148.     begin
  149.     GotoXY(1,i+1);
  150.     Write(DFrame[4]);
  151.     GotoXY(w+4,i+1);
  152.     Write(DFrame[4]);
  153.     end; {for i}
  154.   GotoXY(1,h+2);
  155.   Write(DFrame[5]);
  156.   for i := 1 to w+2 do
  157.     Write(DFrame[2]);
  158.   Write(DFrame[6]);
  159.   GotoXY(2,1);
  160.   Write(MFrame[4],Copy(title,1,w),MFrame[6]);
  161.   NormalVideo;
  162.   end; {Procedure FrameWindow}
  163.  
  164. Procedure MakeWindow(x,y,w,h,color : byte;
  165.                              title : string);
  166.   begin
  167.   FrameWindow(x,y,w,h,color,title);
  168.   Window(x+2,y+1,x+w+1,y+h);
  169.   end; {Procedure MakeWindow}
  170.  
  171. Procedure ClearWindow(x,y,w,h : byte);
  172.   begin
  173.   Window(x,y,x+w+3,y+h+1);
  174.   ClrScr;
  175.   Window(1,1,80,25);
  176.   end; {Procedure ClearWindow}
  177.  
  178. Procedure Show_Status_Line(title : string);
  179.   begin
  180.   GotoXY(1,25);
  181.   Write(Copy(title,1,79));
  182.   ClrEOL;
  183.   end; {Procedure Show_Status_Line}
  184.  
  185. Procedure Show_Instructions(title : string);
  186.   begin
  187.   GotoXY(80-Length(title),25);
  188.   Write(Copy(title,1,79));
  189.   ClrEOL;
  190.   end; {Procedure Show_Instructions}
  191.  
  192. Procedure Clear_Status_Line;
  193.   begin
  194.   Show_Status_Line('');
  195.   end; {Procedure Clear_Status_Line}
  196.  
  197. Procedure Report_Error(x,y : byte; title : string);
  198.   begin
  199.   GotoXY(x,y);
  200.   BoldVideo;
  201.   Write(title);
  202.   NormalVideo;
  203.   GotoXY(1,24);
  204.   Cursor_On;
  205.   Halt;
  206.   end; {Procedure Report_Error}
  207.  
  208. Procedure Beep;
  209.   var
  210.     i : integer;
  211.   begin
  212.   for i := 1 to 3 do
  213.     begin
  214.     Sound(1500);
  215.     Delay(100);
  216.     NoSound;
  217.     Delay(10);
  218.     end; {for}
  219.   end; {Procedure Beep}
  220.  
  221. Procedure Buzz;
  222.   var
  223.     i : integer;
  224.   begin
  225.   for i := 1 to 3 do
  226.     begin
  227.     Sound(500);
  228.     Delay(100);
  229.     NoSound;
  230.     Delay(10);
  231.     end; {for}
  232.   end; {Procedure Buzz}
  233.  
  234. Procedure Mark_Time;
  235.   const
  236.     time_count : byte = 0;
  237.   begin
  238.   case time_count of
  239.     0 : Write('-');
  240.     1 : Write('\');
  241.     2 : Write('|');
  242.     3 : Write('/');
  243.     end; {case}
  244.   time_count := (time_count + 1) mod 4;
  245.   Write(^H);
  246.   end; {Procedure Mark_Time}
  247.  
  248. Procedure Zero_Time(var time : time_set);
  249.   begin
  250.   with time do
  251.     begin
  252.     yr := 0;
  253.     mo := 0;
  254.     dy := 0;
  255.     hr := 0;
  256.     mi := 0;
  257.     se := 0;
  258.     hu := 0;
  259.     end; {with}
  260.   end; {Procedure Zero_Time}
  261.  
  262. Procedure Get_Current_Time(var time : time_set);
  263.   var
  264.     dw : word;
  265.   begin
  266.   with time do
  267.     begin
  268.     GetDate(yr,mo,dy,dw);
  269.     GetTime(hr,mi,se,hu);
  270.     end;
  271.   end; {Procedure Get_Current_Time}
  272.  
  273. Function Yes : boolean;
  274.   var
  275.     ch    : char;
  276.     valid : boolean;
  277.   begin
  278.   Cursor_On;
  279.   repeat
  280.     ch := Upcase(ReadKey);
  281.     valid := true;
  282.     case ch of
  283.       'Y' : begin
  284.             writeln('Yes');
  285.             Yes := true;
  286.             end; {Yes}
  287.       'N' : begin
  288.             writeln('No');
  289.             Yes := false;
  290.             end; {No}
  291.     else
  292.       valid := false;
  293.     end; {case}
  294.   until valid;
  295.   Cursor_Off;
  296.   end; {Function Yes}
  297.  
  298. Function TwoDigit(arg : integer) : string;
  299.   begin
  300.   TwoDigit := Chr((arg div 10) + Ord('0'))
  301.             + Chr((arg mod 10) + Ord('0'));
  302.   end; {Function TwoDigit}
  303.  
  304. Function ThreeDigit(arg : integer) : string;
  305.   var
  306.     hundreds,barg : integer;
  307.   begin
  308.   hundreds := arg div 100;
  309.   barg := arg - 100*hundreds;
  310.   ThreeDigit := Chr(hundreds + Ord('0')) + TwoDigit(barg);
  311.   end; {Function ThreeDigit}
  312.  
  313. Procedure Convert_Blanks(var field : string);
  314.   var
  315.     i : integer;
  316.   begin
  317.   for i := length(field) downto 1 do
  318.     if field[i] = ' ' then
  319.       field[i] := '0';
  320.   end; {Procedure Convert_Blanks}
  321.  
  322. Function Integer_Value(buffer : string;
  323.                  start,length : integer) : integer;
  324.   var
  325.     answer,result : integer;
  326.   begin
  327.   buffer := Copy(buffer,start,length);
  328.   Convert_Blanks(buffer);
  329.   Val(buffer,answer,result);
  330.   if result = 0 then
  331.     Integer_Value := answer
  332.   else
  333.     Integer_Value := 0;
  334.   end; {Function Integer_Value}
  335.  
  336. Function Real_Value(buffer : string;
  337.               start,length : integer) : double;
  338.   var
  339.     result : integer;
  340.     answer : double;
  341.   begin
  342.   buffer := Copy(buffer,start,length);
  343.   Convert_Blanks(buffer);
  344.   if buffer = '' then
  345.     buffer := '0';
  346.   Val(buffer,answer,result);
  347.   if result = 0 then
  348.     Real_Value := answer
  349.   else
  350.     Real_Value := 0.0;
  351.   end; {Function Real_Value}
  352.  
  353. Function File_Exists(filename : string) : boolean;
  354.   var
  355.     filehandle : text;
  356.   begin
  357.   Assign(filehandle,filename);
  358.   {$i-} Reset(filehandle); {$i+}
  359.   if IOResult = 0 then
  360.     begin
  361.     File_Exists := true;
  362.     Close(filehandle);
  363.     end {if}
  364.   else
  365.     File_Exists := false;
  366.   end; {Function File_Exists}
  367.  
  368. Function Select_File(title,pattern,default : string;
  369.                                    x,y,w,h : byte) : string;
  370.   var
  371.     choice         : char;
  372.     start,stop,
  373.     count,select,i : word;
  374.     dirinfo        : SearchRec;
  375.     filedata       : array [1..50] of string;
  376.   begin
  377.   Cursor_Off;
  378.   FindFirst(pattern,AnyFile,dirinfo);
  379.   count := 0;
  380.   select := 1;
  381.   while DosError = 0 do
  382.     begin
  383.     count := count + 1;
  384.     filedata[count] := dirinfo.name;
  385.     if filedata[count] = default then
  386.       select := count;
  387.     FindNext(dirinfo);
  388.     end; {while}
  389.   w := IMax(12,w);
  390.   h := IMin(h,IMax(1,count));
  391.   MakeWindow(x,y,w,h,white,title);
  392.   if count = 0 then
  393.     begin
  394.     BoldVideo;
  395.     Write('No files!');
  396.     Delay(1000);
  397.     NormalVideo;
  398.     Window(1,1,80,25);
  399.     GotoXY(1,25);
  400.     ClrEOL;
  401.     GotoXY(1,24);
  402.     Cursor_On;
  403.     Halt;
  404.     end {if}
  405.   else
  406.     begin
  407.     start := IMin(count - h + 1,select);
  408.     stop  := start + h - 1;
  409.     repeat
  410.       ClrScr;
  411.       for i := start to stop do
  412.         begin
  413.         GotoXY(1,i-start+1);
  414.         if i = select then BoldVideo;
  415.         Write(Copy(filedata[i],1,w));
  416.         if i = select then NormalVideo;
  417.         end; {for i}
  418.       choice := ReadKey;
  419.       if choice = #0 then
  420.         begin
  421.         choice := ReadKey;
  422.         case choice of
  423.           Up : begin
  424.                select := IMax(1,select-1);
  425.                if select < start then
  426.                  begin
  427.                  start := select;
  428.                  stop  := start + h - 1;
  429.                  end; {if}
  430.                end; {Up}
  431.           Dn : begin
  432.                select := IMin(count,select+1);
  433.                if select > stop then
  434.                  begin
  435.                  stop  := select;
  436.                  start := stop - h + 1;
  437.                  end; {if}
  438.                end; {Dn}
  439.           end; {case}
  440.         end; {if}
  441.     until choice = CR;
  442.     Select_File := filedata[select];
  443.     Delay(500);
  444.     end; {else}
  445.   MakeWindow(x,y,w,h,lightgray,title);
  446.   Window(1,1,80,25);
  447.   end; {Function Select_File}
  448.  
  449. Function Select_Option(menu : options;
  450.              number,x,y,w,h : byte) : byte;
  451.   var
  452.     choice              : char;
  453.     start,stop,select,i : word;
  454.   begin
  455.   Cursor_Off;
  456.   h := IMin(h,number);
  457.   select := 1;
  458.   MakeWindow(x,y,w,h,white,menu[0]);
  459.   start := IMin(number - h + 1,select);
  460.   stop  := start + h - 1;
  461.   repeat
  462.     ClrScr;
  463.     for i := start to stop do
  464.       begin
  465.       GotoXY(1,i-start+1);
  466.       if i = select then BoldVideo;
  467.       Write(menu[i]);
  468.       if i = select then NormalVideo;
  469.       end; {for i}
  470.     choice := ReadKey;
  471.     if choice = #0 then
  472.       begin
  473.       choice := ReadKey;
  474.       case choice of
  475.         Up : begin
  476.              select := IMax(1,select-1);
  477.              if select < start then
  478.                begin
  479.                start := select;
  480.                stop  := start + h - 1;
  481.                end; {if}
  482.              end; {Up}
  483.         Dn : begin
  484.              select := IMin(number,select+1);
  485.              if select > stop then
  486.                begin
  487.                stop  := select;
  488.                start := stop - h + 1;
  489.                end; {if}
  490.              end; {Dn}
  491.         end; {case}
  492.       end; {if}
  493.   until choice = CR;
  494.   Select_Option := select;
  495.   Delay(500);
  496.   MakeWindow(x,y,w,h,lightgray,menu[0]);
  497.   Window(1,1,80,25);
  498.   end; {Function Select_Option}
  499.  
  500. end.
  501.